<template>
  <div class="app-container">
    <div class="container ">
      <el-row :gutter="10" class="filter-container">
        <el-col :span="15">
          <el-button
            v-waves
            class="filter-item margin-left20"
            type="primary"
            size="mini"
            @click="submitForm('open')"
          >
            <i class="el-icon-circle-plus-outline" />&nbsp;新增
          </el-button>
          <el-upload
            class="upload-demo"
            :show-file-list="false"
            action="http://10.10.10.11:9006/file/upload"
            :before-upload="beforeAvatarUpload"
            :headers="upHeaders"
            accept=".xls,.xlsx"
            :on-success="handleAvatarSuccess"
          >
            <el-button
              size="mini"
              class="filter-item margin-left20"
              type="primary"
            ><i class="el-icon-circle-plus-outline" />&nbsp;导入</el-button>
          </el-upload>
          <el-button
            v-waves
            class="filter-item margin-left20 upload-demo"
            type="primary"
            size="mini"
            @click="outloadFile"
          >
            <i class="el-icon-download" />&nbsp;导出
          </el-button>
          <el-button
            v-waves
            class="filter-item margin-left20 upload-demo"
            type="primary"
            size="mini"
            @click="downloadFile"
          >
            下载导入模板
          </el-button>
        </el-col>
        <el-col :span="9" style="text-align: right;">
<!--          :disabled="disableSelectDept"-->
          <el-select
            v-show="!disableSelectDept"
            v-model="listQuery.departId"
            style="padding-right:175px"
            placeholder="全部部门"
            size="mini"
            clearable
            @change="queryDepartC"
          >
            <el-option
              v-for="item in options1"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
          <el-input
            v-model="listQuery.search"
            style="width:130px;padding-right:12px"
            :placeholder="placeholderName"
            size="mini"
          />
          <el-button size="mini" type="primary" @click="getList">
            搜索
          </el-button>
        </el-col>
        <!-- <el-col :span="4" style="padding-right:50px;text-align: right;">
          <el-select
            v-model="listQuery.departId"
            placeholder="请选择部门"
            size="mini"
            clearable
            @change="queryDepartC"
          >
            <el-option
              v-for="item in options1"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-col>
        <el-col :span="4">
          <el-input
            v-model="listQuery.search"
            style="width:100%"
            placeholder="请输入软件名称"
            size="mini"
          >
            <i slot="suffix" class="el-input__icon el-icon-search" @click="getList" />
          </el-input>
        </el-col> -->
      </el-row>
      <div>
        <!-- 删除资产 -->
        <el-dialog
          title="删除资产"
          :visible.sync="delUserdialogV"
          width="25%"
          center
        >
          <div class="text-algin-center">
            <el-avatar :size="60" src="../../assets/icons_slices/img_opo_tip.png">
              <img src="../../assets/icons_slices/img_opo_tip.png">
            </el-avatar>
            <h3>确定删除吗？</h3>
            <span>删除后不可恢复</span>
          </div>
          <span slot="footer" class="dialog-footer">
            <el-button type="danger" size="mini" @click="delUserdialogV = false">删除</el-button>
            <el-button size="mini" @click="delUserdialogV = false">取 消</el-button>
          </span>
        </el-dialog>
        <!-- 回收资产 -->
        <el-dialog
          title="删除资产"
          :visible.sync="recUserdialogV"
          width="25%"
          center
        >
          <div class="text-algin-center">
            <el-avatar :size="60" src="../../assets/icons_slices/img_opo_tip.png">
              <img src="../../assets/icons_slices/img_opo_tip.png">
            </el-avatar>
            <h3>确定删除资产吗？</h3>
            <!-- <span>回收后已授权软件将不用</span> -->
          </div>
          <span slot="footer" class="dialog-footer">
            <el-button type="danger" size="mini" @click="handleRecover('do')">删除</el-button>
            <el-button size="mini" @click="recUserdialogV = false">取 消</el-button>
          </span>
        </el-dialog>
      </div>
      <el-table
        v-loading="listLoading"
        element-loading-text="正在加载中..."
        element-loading-background="rgba(0, 0, 0, 0.5)"
        :data="list"
        border
        size="mini"
        fit
      >
        <el-table-column align="center" label="序号">
          <template slot-scope="scope">
            {{ scope.$index+1 + ((listQuery.page-1) * listQuery.limit ) }}
          </template>
        </el-table-column>
        <el-table-column label="软件编号" align="center" width="200px">
          <template slot-scope="scope">
            <!-- <span>{{ scope.row.sizeWithUnit }}</span> -->
            {{ scope.row.softNumber }}
          </template>
        </el-table-column>
        <el-table-column label="软件名称" align="center" width="200px">
          <template slot-scope="scope">
            {{ scope.row.name }}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="软件版本"
          width="230px"
          class="trinExceeds"
        >
          <template slot-scope="scope">
            <div class="strinExceeds" :title="scope.row.softVersion">{{ scope.row.softVersion }}</div>
          </template>
        </el-table-column>
        <el-table-column label="软件类型" align="center" width="200px">
          <template slot-scope="scope">
            {{ typeToName(scope.row.typeId,'typeId') }}
          </template>
        </el-table-column>
        <el-table-column label="采购部门" align="center" width="200px">
          <template slot-scope="scope">
            {{ typeToName(scope.row.departId,'departId') }}
          </template>
        </el-table-column>
        <el-table-column label="所在网络" align="center" width="200px">
          <template slot-scope="scope">
            {{ scope.row.networkType ==1 ? '内网' : '外网' }}
          </template>
        </el-table-column>
        <el-table-column label="是否国内" align="center" width="200px">
          <template slot-scope="scope">
            {{ scope.row.softFrom ==1 ? '国内' : '国外' }}
          </template>
        </el-table-column>
        <!-- <el-table-column label="用途" align="center" width="200px">
          <template slot-scope="scope">
            抗DDOS攻击
            {{ scope.row.purpose }}
          </template>
        </el-table-column> -->
        <el-table-column label="采购时间" align="center" width="200px">
          <template slot-scope="scope">
            {{ scope.row.purchaseDate }}
          </template>
        </el-table-column>
        <el-table-column label="采购金额（单位：元）" align="center" width="200px">
          <template slot-scope="scope">
            {{ scope.row.purchaseAmount }}
          </template>
        </el-table-column>
        <el-table-column label="许可类型" align="center" width="120px">
          <template slot-scope="scope">
            {{ scope.row.permitType ==1 ? '数量授权' : '场地授权' }}
          </template>
        </el-table-column>
        <el-table-column label="许可数量" align="center" width="230px" class="strinExceeds">
          <template slot-scope="scope">
            <div class="strinExceeds" :title="scope.row.permitCount">{{ scope.row.permitCount }}</div>
          </template>
        </el-table-column>
        <el-table-column label="授权方式" align="center" width="180px">
          <template slot-scope="scope">
            {{ scope.row.softCache==1 ? '永久授权' : scope.row.softCache==2 ? '年度授权' : '无授权' }}
          </template>
        </el-table-column>
        <el-table-column label="序列号" align="center" width="100px">
          <template slot-scope="scope">
            <el-button type="text" @click="openXLHDetails(scope.row)">详情</el-button>
          </template>
        </el-table-column>
        <el-table-column label="使用范围" align="center" width="200px">
          <template slot-scope="scope">
            {{ typeToName(scope.row.useRange,'useRange') == '无'?scope.row.useRange:
              typeToName(scope.row.useRange,'useRange') }}
            <!-- {{ scope.row.useRange }} -->
          </template>
        </el-table-column>
        <el-table-column label="使用状态" align="center" width="180px">
          <template slot-scope="scope">
            {{ scope.row.useState ==1 ? '正在使用' : '停止使用' }}
          </template>
        </el-table-column>
        <el-table-column label="许可期限" align="center" width="120px">
          <template slot-scope="scope">
            {{ scope.row.permitEndDate? scope.row.permitEndDate.slice(0,10) : '无' }}
          </template>
        </el-table-column>
        <el-table-column label="管理员" align="center" width="120px">
          <template slot-scope="scope">
            {{ scope.row.manageName }}
          </template>
        </el-table-column>
        <el-table-column label="技术员" align="center" width="200px">
          <template slot-scope="scope">
            {{ scope.row.technologyName }}
          </template>
        </el-table-column>
        <el-table-column label="技术员联系方式" align="center" width="200px">
          <template slot-scope="scope">
            {{ scope.row.technologyPhone }}
          </template>
        </el-table-column>
        <!-- <el-table-column label="备注" align="center" width="200px">
          <template slot-scope="scope">
            {{ scope.row.remark }}
          </template>
        </el-table-column> -->
        <el-table-column
          width="320"
          fixed="right"
          align="left"
        >
          <template slot="header" style="text-align: center;">
            <span>操作</span>
          </template>
          <template slot-scope="scope">
            <el-button
              :disabled="!isMyDept(scope.row.departId)&&!isAdmin1"
              style="width: 80px"
              type="primary"
              size="mini"
              @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button>
            <el-button
              :disabled="!isMyDept(scope.row.departId)&&!isAdmin1"
              style="width: 80px"
              type="danger"
              size="mini"
              @click="handleRecover(scope.$index, scope.row)"
            >删除</el-button>
            <!-- <el-button
              type="danger"
              size="mini"
              @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button> -->
            <el-button
              style="width: 80px"
              v-if="scope.row.fileMd5 != ''"
              type="primary"
              size="mini"
              @click="handleEdit1(scope.$index, scope.row)"
            >下载</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" layout="total, sizes, prev, pager, next, jumper" @pagination="getList" />
      <p class="margin-left30">注：1.软件名称：采用《水利固定资产分类与代码》（SL 731—2015）中水利固定资产代码表中“名称”，如：</p>
      <p class="margin-left30">（1）WPS office2019 ，软件名称应为：办公软件；</p>
      <p class="margin-left30">（2）windows 7，软件名称应为：操作系统。</p>
      <p class="margin-left30">2.软件版本：填写具体版本，如WPS office2019，windows7。</p>
      <p class="margin-left30">3.软件类型：分商业软件、OEM软件、自开发软件。</p>
      <p class="margin-left30">4.许可类型：分场地授权、数量授权。</p>
      <p class="margin-left30">5.授权方式：分永久授权、年度授权。</p>
      <p class="margin-left30">6.商业软件，软件名称或版本不同的，使用不同的软件编号，软件名称或版本相同的，采购时间、采购金额、许可类型、许可数量、</p>
      <p class="margin-left30">可使用版本、许可期限、序列号等任一不相同的，使用不同的软件编号；</p>
      <p class="margin-left30">7.通过受赠、调剂等方式获得的商业软件，不填写采购时间、采购金额。
      </p><p class="margin-left30">8.OEM软件，不填写采购时间、采购金额、许可类型、许可数量、可使用版本、许可期限、序列号等信息。软件名称或软件版本不同的OEM软件，</p>
      <p class="margin-left30">使用不同的软甲编号。</p>
      <p class="margin-left30">9.免费软件不在台账中体现。</p>
      <p class="margin-left30">10.自行组织开发软件，依据研制开发部门的项目决算情况登记台账信息，升级、改版后使用不同的软件编号。</p>
    </div>
    <!-- 添加资产弹框 -->
    <el-dialog
      :title="titleStatus"
      :visible.sync="addUserdialogV"
      width="85%"
      :before-close="handleClose"
      center
    >
      <el-form
        ref="ruleForm"
        class="formInner"
        label-width="120px"
        :rules="rules"
        size="mini"
        :inline="true"
        :model="formAddUser"
      >
        <el-row>
          <el-col v-if="formAddUser.id" :span="8" prop="softNumber">
            <el-form-item label="软件编号:">
              <el-input v-model="formAddUser.softNumber" :disabled="true" />
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="软件名称:" prop="nameId">
              <div class="block">
                <el-cascader
                  v-model="formAddUser.nameId"
                  placeholder="请选择"
                  :options="optionsP"
                  filterable
                  clearable
                  :show-all-levels="false"
                  style="width:163px;float: left"
                />
              </div>
              <!-- <el-select v-model="formAddUser.nameId" placeholder="请选择">
                <el-option
                  v-for="item in options9"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select> -->
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="软件版本:" prop="softVersion">
              <el-input v-model="formAddUser.softVersion" maxlength="30" />
            </el-form-item>
          </el-col>
          <el-col v-if="formAddUser.id == ''" :span="8">
            <el-form-item label="序列号:">
              <el-input
                v-model="formAddUser.secretKey"
                :title="formAddUser.secretKey"
                :disabled="(formAddUser.typeId == '60660672704221184'? true : false) || formAddUser.secretKeyType == 0"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="软件类型:" prop="typeId">
              <el-select
                v-model="formAddUser.typeId"
                placeholder="请选择"
                @change="PurchAmountC"
              >
                <el-option
                  v-for="item in options"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="采购部门:" prop="departId">
              <el-select v-model="formAddUser.departId" placeholder="请选择">
                <el-option
                  v-for="item in options1"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="所在网络:" prop="networkType">
              <el-select v-model="formAddUser.networkType" placeholder="请选择">
                <el-option
                  v-for="item in options3"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="是否国内:" prop="softFrom">
              <el-select v-model="formAddUser.softFrom" placeholder="请选择">
                <el-option
                  v-for="item in options4"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="8">
            <el-form-item  label="用途:" >
              <el-select v-model="value" placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item> -->
          <!-- </el-col> -->
          <el-col :span="8">
            <el-form-item label="许可类型:">
              <el-select
                v-model="formAddUser.permitType"
                placeholder="请选择"
                :disabled="formAddUser.typeId == '60660672704221184'? true : false"
              >
                <el-option
                  v-for="item in options5"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8" style="padding-right: 5px;">
            <el-form-item label="采购金额:" prop="userName">
              <el-input
                v-model="formAddUser.purchaseAmount"
                type="number"
                min="0"
                onkeyup="value=value.replace('-','')"
                :disabled="formAddUser.typeId == '60660672704221184'? true : false"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="授权方式:" prop="permitMode">
              <el-select
                v-model="formAddUser.permitMode"
                placeholder="请选择"
                @change="permitModeC"
              >
                <el-option
                  v-for="item in options6"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="使用范围:">
              <el-select
                v-model="formAddUser.useRange"
                placeholder="请选择"
                :disabled="formAddUser.typeId == '60660672704221184'? true : false"
              >
                <el-option
                  v-for="item in options10"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="使用状态:" prop="useState">
              <el-select
                v-model="formAddUser.useState"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in options8"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item class="datetime" label="采购时间:">
              <div class="block">
                <el-date-picker
                  v-model="formAddUser.purchaseDate"
                  :disabled="formAddUser.typeId == '60660672704221184'? true : false"
                  style="width:85%;"
                  type="date"
                  placeholder="选择日期"
                  value-format="yyyy-MM-dd"
                />
              </div>
            </el-form-item>
          </el-col>
          <el-col v-if="formAddUser.permitMode !== '1' && formAddUser.permitMode !== '3'" :span="8">
            <el-form-item class="datetime" label="许可期限:">
              <div class="block">
                <el-date-picker
                  v-model="formAddUser.permitEndDate"
                  title="请选择许可截止期限"
                  :disabled="formAddUser.typeId == '60660672704221184'? true : false"
                  style="width:85%;"
                  value-format="yyyy-MM-dd"
                  type="date"
                  placeholder="选择日期"
                />
              </div>
            </el-form-item>
          </el-col>
          <el-col v-if="formAddUser.permitMode == '1' || formAddUser.permitMode == '3'" :span="8">
            <el-form-item label="许可期限:">
              <el-input
                v-model="formAddUser.permitEndDate"
                value-format="yyyy-MM-dd"
                :disabled="(formAddUser.typeId == '60660672704221184' || formAddUser.permitMode == '1'
                  || formAddUser.permitMode == '3')? true : false"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="许可数量:" prop="userName">
              <el-input
                v-model="formAddUser.permitCount"
                onkeyup="value=value.replace('-','')"
                :disabled="formAddUser.typeId == '60660672704221184'? true : false"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="管理员:" prop="userName">
              <el-input v-model="formAddUser.manageName" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="技术员:" prop="userName">
              <el-input v-model="formAddUser.technologyName" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="技术员电话:" prop="userName">
              <el-input v-model="formAddUser.technologyPhone" maxlength="11" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col v-if="formAddUser.id" :span="8">
            <el-form-item label="序列号:">
              <el-input
                v-model="formAddUser.secretKey"
                :title="formAddUser.secretKey"
                :disabled="(formAddUser.typeId == '60660672704221184'? true : false )"
              />
<!--              :disabled="(formAddUser.typeId == '60660672704221184'? true : false || formAddUser.secretKeyType == 0)"-->
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="检索名称:">
              <el-input v-model="formAddUser.sysDisplayName" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="检索版本:">
              <el-input v-model="formAddUser.sysDisplayVersion" />
            </el-form-item>
          </el-col>
          <el-col v-if="formAddUser.id" :span="12" :offset="1">
            <el-row>
              <el-col :span="12">
                <el-form-item>
                  <webuploader2 v-if="isShowUploadBtn" @setFileUrl="setFileUrl" />
                  <div v-if="!isShowUploadBtn" >
                    {{formAddUser.originalFileName}}
                    <span class="itemDone">上传完成</span><span  @click="handleClose2(1)" class="itemDel">删除</span>
                    <br>
                    <p class="itemDone" style="color: red">如需更换请先删除已上传文件</p>
                  </div>
                </el-form-item>
              </el-col>
              <el-col
                v-if="isShowFm5"
                :span="16"
                style="text-algin:left;color: red"
              >
                <!-- <span style="font-size:14px;color: red">已上传过文件,点击上传将替换</span> -->
              </el-col>
            </el-row>
          </el-col>
          <!-- <el-col v-if="formAddUser.fileMd5 != ''" :span="8">
            <el-form-item v-if="formAddUser.id">
              <span style="font-size:14px;margin-top:30px;color: red">已上传过文件,点击上传将替换</span>
            </el-form-item>
          </el-col> -->
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" size="mini" @click="submitForm('ruleForm')">确 定</el-button>
        <el-button size="mini" @click="handleClose">取 消</el-button>
      </span>
    </el-dialog>
    <el-dialog
      :title="'序列号详情--'+softTitle"
      :visible.sync="dialogVisible"
      width="40%"
      center
    >
      <el-table
        :data="secretList"
        style="width: 100%;
         max-height: 360px;
        overflow-y: scroll;"
      >
        <el-table-column align="center" label="序号" width="50">
          <template slot-scope="scope">
            {{ scope.$index+1 }}
          </template>
        </el-table-column>
        <el-table-column
          label="秘钥"
          width=""
          align="center"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.secretKey }}</span>
          </template>
        </el-table-column>
        <el-table-column label="数量">
          <template slot-scope="scope">
            <span>{{ scope.row.totalNum }}</span>
          </template>
        </el-table-column>
        <!--        <el-table-column label="修改时间">-->
        <!--          <template slot-scope="scope">-->
        <!--            <span>{{ scope.row.updateTime }}</span>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column label="说明">-->
        <!--          <template slot-scope="scope">-->
        <!--            <span>{{ scope.row.descr }}</span>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!-- <el-table-column
          label="操作"
          width="300"
          align="center"
        >
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="mini"
              @click="softSecretDel(scope.row,'edit')"
            >编辑</el-button>
            <el-button
              v-if="scope.row.type == 0"
              type="danger"
              size="mini"
              @click="softSecretDel(scope.row,'del')"
            >删除</el-button>
            <el-button
              v-if="scope.row.type == 1"
              type="warning"
              size="mini"
              @click="softSecretDel(scope.row,'cehui')"
            >撤回</el-button>
          </template>
        </el-table-column> -->
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" type="primary" @click="dialogVisible = false">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { assetsPage, assetsPut, assetsAdd, assetsRecycle, assetsImport, assetsExport } from '@/api/assetSoft'
import Pagination from '@/components/Pagination'
import { getToken } from '@/utils/auth'
import { softSecretApply, softSecretSoft, softTypeList,
  softNamePage, softList, softAdd, softDel, softPut, softDetailSecret } from '@/api/softManage'
import {
  departmentList
} from '@/api/department'
import { userList, userAdd
  , userDel, userPut, userPermission, userPasswordPut } from '@/api/user'
import webuploader2 from '@/components/webuploader2/webuploader2'
import { getCookie, setCookie, removeCookie } from '@/utils/cookie'
export default {
  computed: {
    isManage() {
      // console.log(getCookie('userInfo').realName)
      if (getCookie('userInfo')) {
        return JSON.parse(getCookie('userInfo')).roleType === 1024 ||
        JSON.parse(getCookie('userInfo')).roleType === 1025
      } else {
        return false
      }
    }
  },
  components: { Pagination, webuploader2 },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      isAdmin1: false,
      isShowUploadBtn: false,
      options10: [],
      softTitle: '',
      secretList: [],
      xuliehaoCache: '',
      dialogVisible: false,
      upHeaders: {
        ACCESS_TOKEN: getToken()
      },
      recUserdialogV: false,
      datevalue2: null,
      datevalue1: null,
      isUserEdit: false,
      titleStatus: '添加资产',
      rules: {
        softVersion: [
          { required: true, message: '请输入内容', trigger: 'blur' }
        ],
        secretKey: [
          { required: true, message: '请输入内容', trigger: 'blur' }
        ],
        typeId: [
          { required: true, message: '请选择', trigger: 'blur' }
        ],
        networkType: [
          { required: true, message: '请选择', trigger: 'blur' }
        ],
        departId: [
          { required: true, message: '请选择', trigger: 'blur' }
        ],
        softFrom: [
          { required: true, message: '请选择', trigger: 'blur' }
        ],
        permitMode: [
          { required: true, message: '请选择', trigger: 'blur' }
        ],
        useState: [
          { required: true, message: '请选择', trigger: 'blur' }
        ],
        softNumber: [
          { required: true, message: '软件编号', trigger: 'blur' }
        ],
        nameId: [
          { required: true, message: '请选择', trigger: 'blur' }
        ],
        phone: [
          { required: true, message: '请输入手机号', trigger: 'blur' },
          { min: 11, max: 11, message: '手机号长度不对', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入内容', trigger: 'blur' },
          { min: 2, max: 25, message: '长度在 6 到 25 个字符', trigger: 'blur' }
        ]
      },
      formAddUser: {
        originalFileName: '',
        secretKeyNum: 1,
        'departId': '61291134137036800',
        'descr': '',
        'id': '',
        'imgs': '',
        'logo': '',
        'name': '',
        manageName: '',
        'nameId': [],
        'networkType': '1',
        'permitCount': '',
        'permitEndDate': '永久',
        'permitMode': '1',
        'permitType': '1',
        'purchaseAmount': '',
        'purchaseDate': '',
        'remark': '',
        'secretKey': 'xxx1,6|xxxx3,7',
        'secretKeyType': '1',
        'serialNumber': '',
        'softFrom': '1',
        'softIndex': '',
        'softNumber': '',
        'softVersion': '',
        'sysDisplayName': '',
        'sysDisplayVersion': '',
        'technologyName': '',
        'technologyPhone': '',
        'typeId': '58590645649817600',
        'useRange': '0',
        'useState': '1',
        'year': ''
      },
      addUserdialogV: false,
      delUserdialogV: false,
      value1: '1',
      value2: '1',
      total: 10,
      list: null,
      listLoading: false,
      disableSelectDept: false, // 是否可选择部门
      listQuery: {
        departId: '',
        search: '',
        page: 1,
        limit: 10,
        menuFrom: 1
      },
      options: [{
        value: '1',
        label: '商业软件'
      }, {
        value: '2',
        label: 'OEM软件'
      }, {
        value: '3',
        label: '自开发软件'
      }],
      options1: [{
        value: '1',
        label: '技术部'
      }, {
        value: '2',
        label: '合同部'
      }],
      options2: [{
        value: '1',
        label: '账号密码'
      }, {
        value: '2',
        label: '关联登录'
      }],
      options3: [{
        value: '1',
        label: '内网'
      }, {
        value: '2',
        label: '外网'
      }],
      options4: [{
        value: '1',
        label: '国内'
      }, {
        value: '2',
        label: '国外'
      }],
      options5: [{
        value: '1',
        label: '数量授权'
      }, {
        value: '2',
        label: '场地授权'
      }],
      options6: [{
        value: '1',
        label: '永久授权'
      }, {
        value: '2',
        label: '年度授权'
      }, {
        value: '3',
        label: '无授权'
      }
      ],
      options7: [{
        value: '1',
        label: '公司全体'
      }, {
        value: '2',
        label: '计划合同部'
      }, {
        value: '3',
        label: '正版软件服务器'
      }
      ],
      options8: [{
        value: '1',
        label: '正在使用'
      }, {
        value: '2',
        label: '停止使用'
      }
      ], options9: [{
        value: 'zhinan',
        label: '指南',
        children: [{
          value: 'shejiyuanze',
          label: '设计原则',
          children: [{
            value: 'yizhi',
            label: '一致'
          }, {
            value: 'fankui',
            label: '反馈'
          }, {
            value: 'xiaolv',
            label: '效率'
          }, {
            value: 'kekong',
            label: '可控'
          }]
        }, {
          value: 'daohang',
          label: '导航',
          children: [{
            value: 'cexiangdaohang',
            label: '侧向导航'
          }, {
            value: 'dingbudaohang',
            label: '顶部导航'
          }]
        }]
      }],
      editPassword: false,
      value: '1',
      cacheId: null,
      isShowFm5: false,
      placeholderName: '搜索软件版本'
    }
  },
  created() {
    if (JSON.parse(getCookie('userInfo')).roleType === 1024) {
      this.isAdmin1 = true
    } else {
      this.isAdmin1 = false
    }
    this.getDepartmentList()
    this.softNamePage()
    this.getTypeList()
    this.fetchData()
  },
  methods: {
    isMyDept(deptId) {
      const user = JSON.parse(getCookie('userInfo'))
      console.log(user.departmentId === '67515117203329024')
      if (user.departmentId === '67515117203329024') {
        // 总调度中心可管理所有
        return true
      }
      return user.departmentId === deptId
    },
    queryDepartC(val) {
      // this.getList()
      if (val) {
        this.placeholderName = '全部软件'
      } else {
        this.placeholderName = '全部软件'
      }
    },
    PurchAmountC(val) {
      if (val == '60660672704221184') {
        this.formAddUser.useRange = ''
        this.formAddUser.permitEndDate = '永久'
        this.formAddUser.permitType = '1'
        this.formAddUser.purchaseAmount = ''
        this.formAddUser.purchaseDate = ''
        this.formAddUser.permitCount = ''
        this.formAddUser.secretKeyType = '0'
        this.formAddUser.secretKey = ''
      }
    },
    permitModeC(val) {
      if (val == 1) {
        this.formAddUser.permitEndDate = '永久'
      } else if (val == 2) {
        this.formAddUser.permitEndDate = ''
      } else {
        this.formAddUser.permitEndDate = '无'
      }
    },
    setFileUrl(params) {
      this.formAddUser.fileMd5 = params
    },
    typeToName(params, type) {
      if (type == 'typeId') {
        return this.options.filter(item => item.id == params)[0]
          ? this.options.filter(item => item.id == params)[0].name : '公司全体'
      } else if (type == 'departId') {
        return this.options1.filter(item => item.id == params)[0]
          ? this.options1.filter(item => item.id == params)[0].name : '无'
      } else if (type == 'useRange') {
        return this.options10.filter(item => item.id + '' == params)[0]
          ? this.options10.filter(item => item.id == params)[0].name : '无'
      }
    },
    getTypeList() {
      softTypeList({
        limit: 20,
        page: 1
      }).then(res => {
        if (res.code === 200) {
          this.options = []
          // this.options10 = [{
          //   id: '0',
          //   name: '公司全体'
          // }]
          res.data.data.map(item => {
            if (item.id !== '1025' && item.id !== '55904214559285248') {
              this.options.push(item)
              // this.options10.push(item)
            }
          })
        }
      })
    },
    getDepartmentList() {
      departmentList({
        limit: 50,
        page: 1
      }).then(res => {
        if (res.code === 200) {
          this.options1 = []
          this.options10 = [{
            id: '0',
            name: '公司全体'
          }]
          res.data.data.map(item => {
            if (item.id !== '1025' && item.id !== '55904214559285248') {
              this.options10.push(item)
              this.options1.push(item)
            }
          })
          console.log('this.options1', this.options1)
          if (this.options1.length === 1) {
            this.listQuery.departId = this.options1[0].id
            this.disableSelectDept = true
          } else {
            this.disableSelectDept = false
          }
        }
      })
    },
    softNamePage() {
      softNamePage({
        limit: 200,
        page: 1
      }).then(res => {
        if (res.code === 200) {
          this.optionsP = res.data.data
        }
      })
    },
    handleClose1() {
      this.dialogVisible = false
    },
    openXLHDetails(params, type) {
      softDetailSecret({
        id: params.id
      }).then(res => {
        if (res.code == 200) {
          this.softTitle = params.softVersion
          this.secretList = res.data.data
          var arrlist = []
          res.data.data.map(item => {
            if (item.secretKey) {
              arrlist.push(item.secretKey)
            }
          })
          if (arrlist.length > 0) {
            this.xuliehaoCache = arrlist.join(',')
          } else {
            this.xuliehaoCache = ''
          }
          if (type != true) {
            this.dialogVisible = true
          }
        }
      })
    },
    downloadFile() {
      const link = document.createElement('a')
      link.style.display = 'none'
      link.setAttribute('download', '信息化软件资产管理台帐-模板')
      link.href = 'http://10.10.10.11:9006/upload/%E6%A8%A1%E6%9D%BF-%E8%BD%AF%E4%BB%B6%E8%B5%84%E4%BA%A7%E7%AE%A1%E7%90%86%E5%8F%B0%E5%B8%90.xlsx'
      document.body.appendChild(link)
      link.click()
    },
    outloadFile() {
      assetsExport(this.listQuery).then(res => {
        if (res.code === 200) {
          // this.getList()
          const link = document.createElement('a')
          link.style.display = 'none'
          link.setAttribute('download', '信息化固定资产管理台帐')
          link.href = res.message
          document.body.appendChild(link)
          link.click()
          // window.open(res.message)
        }
      })
    },
    beforeAvatarUpload(file) {
      const isJPG = file.name.indexOf('xls')
      const isLt2M = file.size / 1024 / 1024 < 200
      if (!isJPG) {
        this.$message.error('上传文件只能是Excel文件!')
      }
      if (!isLt2M) {
        this.$message.error('上传文件大小不能超过 200MB!')
      }
      return isJPG && isLt2M
    },
    handleAvatarSuccess(response, file, fileList) {
      this.listLoading = true
      if (response && response.code === 200) {
        assetsImport({
          filePath: response.data
        }).then(res => {
          if (res.code === 200) {
            // this.getList()
            this.$message.success('导入软件台账申请成功')
            this.listLoading = false
          }
        })
        // this.ruleForm.logo = response.data
        // this.logoUrl = URL.createObjectURL(file.raw)
      } else {
        this.$message.warning('请求异常')
      }
    },
    initData() {
      this.formAddUser = {
        secretKeyNum: 1,
        'departId': '64770000736595968',
        'descr': '',
        'id': '',
        'imgs': '',
        'logo': '',
        'name': '',
        manageName: '',
        'nameId': '',
        'networkType': '1',
        'permitCount': '',
        'permitEndDate': '永久',
        'permitMode': '1',
        'permitType': '1',
        'purchaseAmount': '',
        'purchaseDate': '',
        'remark': '',
        'secretKey': '',
        'secretKeyType': '1',
        'serialNumber': '',
        'softFrom': '1',
        'softIndex': '',
        'softNumber': '',
        'softVersion': '',
        'sysDisplayName': '',
        'sysDisplayVersion': '',
        'technologyName': '',
        'technologyPhone': '',
        'typeId': '58590645649817600',
        'useRange': '0',
        'useState': '1',
        'year': ''
      }
    },
    handleClose(params) {
      this.initData()
      this.getList()
      this.addUserdialogV = false
      this.isShowUploadBtn = false
    },
    handleClose2(tag) {
      this.isShowUploadBtn = true
    },
    submitForm(formName, editPassword) {
      if (formName === 'open') {
        this.initData()
        this.titleStatus = '添加资产'
        this.formAddUser.userName = ''
        this.formAddUser.phone = ''
        this.addUserdialogV = true
        this.formAddUser.id = ''
        this.isUserEdit = false
      } else {
        if (this.formAddUser.typeId + '' === '60660672704221184') {
          this.formAddUser.useRange = '0'
          this.formAddUser.permitEndDate = '永久'
          this.formAddUser.permitType = '1'
          this.formAddUser.purchaseAmount = ''
          this.formAddUser.purchaseDate = ''
          this.formAddUser.permitCount = ''
          this.formAddUser.secretKeyType = 0
          this.formAddUser.secretKey = ''
        }
        // if (this.formAddUser.nameId.length > 0) {
        //   this.formAddUser.nameId = this.formAddUser.nameId[this.formAddUser.nameId.length - 1]
        // }
        if (this.formAddUser.id !== '') {
          this.$refs['ruleForm'].validate((valid) => {
            if (valid) {
              softPut(this.formAddUser).then(res => {
                if (res.code === 200) {
                  this.imageUrl = ''
                  this.addUserdialogV = false
                  this.initData()
                  this.getList()
                }
              })
            }
          })
        } else {
          this.$refs[formName].validate((valid) => {
            if (valid) {
              if (this.formAddUser.secretKey == '') {
                this.formAddUser.secretKeyType = 0
              } else {
                this.formAddUser.secretKeyType = 1
              }

              softAdd(this.formAddUser).then(res => {
                if (res.code === 200) {
                  this.addUserdialogV = false
                  this.initData()
                  this.getList()
                }
              })
              // alert('submit!')
            } else {
              return false
            }
          })
        }
      }
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    },
    handleEdit1(index, row) {
      if (index === 'apply') {
        this.handleDetails(row, 'apply')
      } else {
        // window.location.href = row.downloadUrl
        window.location.href = 'http://10.10.10.11:9006/file/download?id=' + row.id

      }
    },
    handleEdit(index, row) {
      if (row.fileMd5 !== '') {
        this.isShowFm5 = true
      } else {
        this.isShowFm5 = false
      }
      this.titleStatus = '修改资产'
      // this.openXLHDetails(row, true)
      this.addUserdialogV = true
      for (const key in row) {
        this.formAddUser[key] = row[key] + ''
      }
      this.formAddUser.nameId = row.nameId
      this.formAddUser.originalFileName = row.originalFileName
      console.log('this.formAddUser.originalFileName:', this.formAddUser.originalFileName)
      if (!row.originalFileName) {
        this.isShowUploadBtn = true
      }
      softDetailSecret({
        id: row.id
      }).then(res => {
        if (res.code == 200) {
          var arrlist = []
          res.data.data.map(item => {
            if (item.secretKey) {
              arrlist.push(item.secretKey)
            }
          })
          if (arrlist.length > 0) {
            this.formAddUser.secretKey = arrlist.join(',')
          } else {
            this.formAddUser.secretKey = ''
          }
        }
      })
    },
    handleRecover(index, row) {
      if (index == 'do') {
        softDel(
          {
            ids: this.cacheId
          }
        ).then(res => {
          if (res.code == 200) {
            this.recUserdialogV = false
            this.$message.success('删除成功')
            this.getList()
          }
        })
      } else {
        this.recUserdialogV = true
        this.cacheId = row.id
      }
    },
    handleDelete(index, row) {
      this.delUserdialogV = true
    },
    getList() {
      this.listLoading = true
      softList(this.listQuery).then(response => {
        this.list = response.data.data
        this.total = response.totalCount
        this.listLoading = false
      })
    },
    fetchData() {
      this.listLoading = false
      this.getList()
    }
  }
}
</script>
<style>
  .filter-container{
    margin-bottom: 20px;
  }
</style>
<style scoped>
  /deep/.el-table th>.cell {
      display: inline-block;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      position: relative;
      vertical-align: middle;
      padding-left: 10px;
      padding-right: 10px;
      width: 100%;
      text-align: center;
  }
  /deep/.datetime>.el-form-item__label {
    padding-right: 12px;
  }
  /deep/.formInner>.el-select>.el-input{
      width: 166px;
  }
  /deep/.el-select>.el-input {
    width: 163px;
    display: block;
}
  /deep/.el-col-8 {
      text-align: left;
      width: 33.33333%;
  }
  /deep/.el-dialog__body {
    text-align: center;
    padding: 25px 25px 0px;
  }
  .upload-demo{
    display: inline;
    margin-left: 10px;
  }
    .margin-left30 {
        margin-left: 30px;
      font-size: .8rem;
    }
  .text-algin-center {
    text-align: center;
  }
  .container {
    padding: 25px 20px 20px 20px !important;
  }
</style>
